<?php
namespace UserTest\Controller;

use UserTest\Bootstrap;
use \PHPUnit_Framework_TestCase;
use User\Controller\UserController;
use Zend\Http\Request;
use Zend\Mvc\Router\Http\RouteMatch;
use Zend\mvc\Router\Http\TreeRouteStack as HttpRouter;
use Zend\Mvc\MvcEvent;

class UserControllerTest extends PHPUnit_Framework_TestCase
{
    protected $controller;
    protected $request;
    protected $response;
    protected $routeMatch;
    protected $event;
    
    protected function setUp()
    {
    	$serviceManager = Bootstrap::getServiceManager();
    	$this->controller = new UserController();
    	$this->request = new Request();
    	$this->routeMatch = new RouteMatch(array('controller' => 'index'));
    	$this->event = new MvcEvent();
    	$config = $serviceManager->get("Config");
    	$routerConfig = isset($config['router']) ? $config['router'] : array();
    	$router = HttpRouter::factory($routerConfig);
    	$this->event->setRouter($router);
    	$this->event->setRouteMatch($this->routeMatch);
    	$this->controller->setEvent($this->event);
    	$this->controller->setServiceLocator($serviceManager);
    }
    
    public function testIndexActionCanBeAccessed()
    {
    	$this->routeMatch->setParam('action', 'index');
    	$result = $this->controller->dispatch($this->request);
    	$response = $this->controller->getResponse();
    	$this->assertEquals(200, $response->getStatusCode());
    }
    
    public function testLoginActionCanBeAccessed()
    {
    	$this->routeMatch->setParam('action', 'login');
    	$result = $this->controller->dispatch($this->request);
    	$response = $this->controller->getResponse();
    	$this->assertEquals(200, $response->getStatusCode());
    }
    
    public function testRegisterActionCanBeAccessed()
    {
    	$this->routeMatch->setParam('action', 'register');
    	$result = $this->controller->dispatch($this->request);
    	$response = $this->controller->getResponse();
    	$this->assertEquals(200, $response->getStatusCode());
    }
}
?>